﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace MeasurementTools
{
	/// <summary>
	/// Interaction logic for PropertyItem.xaml
	/// </summary>
	public partial class PropertyItem : UserControl
	{
        private bool m_showMe = true;
        private bool m_previewMe = true;
        private int m_itemHeight = 24;
        private int m_fontSizeType = 0;

        SolidColorBrush m_border_BorderBrush;
        SolidColorBrush m_brushBorderBackground;
        SolidColorBrush m_brushBorderSelected;
        SolidColorBrush m_brushTextForeground;

		public PropertyItem()
		{
			this.InitializeComponent();
            m_label.SizeChanged += new SizeChangedEventHandler(m_label_SizeChanged);

            m_border_BorderBrush = FindResource("border_BorderBrush") as SolidColorBrush;
		}

        void m_label_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            hot_area.Margin = new Thickness(m_label.ActualWidth, 0, 0, 0);
        }

        public int ItemHeight
        {
            get { return m_itemHeight; }
        }

        public int FontSizeType
        {
            get { return m_fontSizeType; }
            set
            {
                m_fontSizeType = value;
                if (m_fontSizeType == 1)
                {
                    m_itemHeight = 28;
                    m_label.FontSize = 14;
                }
                else if (m_fontSizeType == 2)
                {
                    m_itemHeight = 32;
                    m_label.FontSize = 16;
                }
                else 
                {
                    m_itemHeight = 24;
                    m_label.FontSize = 12;
                }

                main_grid.Height = m_itemHeight;

            }
        }

        public SolidColorBrush BorderBorderBrush
        {
            get { return m_border_BorderBrush; }
            set { m_border_BorderBrush.Color = value.Color; }
        }

        public string LabelText
        {
            get { return m_label.Content.ToString(); }
            set
            {
                m_label.Content = value;
            }
        }

        public double BackgroundOpacity
        {
            get { return m_border.Background.Opacity; }
            set { m_border.Background.Opacity = value; }
        }

        public bool ShowMe
        {
            get { return m_showMe; }
            set
            {
                m_showMe = value;
                if (m_showMe)
                {
                    textBlock_minus.Visibility = Visibility.Visible;
                    textBlock_plus.Visibility = Visibility.Hidden;

                    if (Visibility == Visibility.Hidden)
                    {
                        Visibility = Visibility.Visible;
                        //var storyboard = this.Resources["VisibleOn"] as Storyboard;
                        //this.BeginStoryboard(storyboard);
                    }
                }
                else
                {
                    textBlock_minus.Visibility = Visibility.Hidden;
                    textBlock_plus.Visibility = Visibility.Visible;

                    if (Visibility == Visibility.Visible)
                    {
                        Visibility = Visibility.Hidden;
                        //var storyboard = this.Resources["VisibleOff"] as Storyboard;
                        //this.BeginStoryboard(storyboard);
                    }
                }
            }
        }

        public bool PreviewMe
        {
            get { return m_previewMe; }
            set
            {
                m_previewMe = value;
                if (m_previewMe)
                {
                    BorderBorderBrush = new SolidColorBrush(Color.FromArgb(255, 0,255,0));
                    BackgroundOpacity = 0.8;

                    if ( Visibility == Visibility.Hidden)
                    {
                        Visibility = Visibility.Visible;
                        //var storyboard = this.Resources["VisibleOn"] as Storyboard;
                        //this.BeginStoryboard(storyboard);
                    }
                }
                else
                {
                    BorderBorderBrush = new SolidColorBrush(Color.FromArgb(50, 255, 255, 0));
                    BackgroundOpacity = 0.1;

                    if (m_showMe)
                    {
                        if ( Visibility == Visibility.Hidden)
                        {
                            Visibility = Visibility.Visible;
                        }
                    }
                    else
                    {
                        if ( Visibility == Visibility.Visible)
                        {
                            Visibility = Visibility.Hidden;
                            //var storyboard = this.Resources["VisibleOff"] as Storyboard;
                            //this.BeginStoryboard(storyboard);
                        }
                    }
                }
            }
        }

        private void Rectangle_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
        	// TODO: Add event handler implementation here.
            ShowMe = !ShowMe;
            if (ShowMe)
            {
                textBlock_minus.Visibility = Visibility.Visible;
                textBlock_plus.Visibility = Visibility.Hidden;
            }
            else
            {
                textBlock_minus.Visibility = Visibility.Hidden;
                textBlock_plus.Visibility = Visibility.Visible;
            }
        }
	}
}